<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FusionCharts v3 Documentation</title>
<link rel="stylesheet" href="Style.css" type="text/css" />
</head>

<body>
<table width="98%" border="0" cellspacing="0" cellpadding="3" align="center">
  <tr> 
    <td><h2 class="pageHeader">Using FusionCharts with C# (ASP.NET)&gt; Charting Data from Forms </h2></td>
  </tr>
  <tr> 
    <td valign="top" class="text"><p>In this section, we'll show you how to use FusionCharts with C# (ASP.NET) to plot data collected in forms. </p>
      <p>We'll build a simple restaurant sales example, where the user will enter the items sold by a restaurant in a given week. This data will be submitted in a form to the server. We'll acquire this data and plot in on a chart. For the sake of simplicity, we wouldn't do any processing on this data. However, your real life applications might process data before presenting it on the chart. </p>
    <p><strong>Before you go further with this page, we recommend you to please see the previous section &quot;Basic Examples&quot; as we start off from concepts explained in that page. </strong></p></td>
  </tr>
  <tr>
    <td valign="top" class="highlightBlock">The code examples contained in this page are present in<span class="codeInline"> Download Package &gt; Code &gt; C# </span> &gt; <span class="codeInline">FormBased</span> folder. </td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Building the Form </td>
  </tr>
  <tr>
    <td valign="top" class="text">The form is contained in <span class="codeInline">Default.aspx</span> and looks as under: </td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_Form.gif" width="445" height="387" class="imageBorder" /></td>
  </tr>
  <tr>
    <td valign="top" class="text">It's a very simple form which submits to itself. As such, we wouldn't go into the code of this form. You can directly open the source from download and see it. </td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Requesting the data and Creating the Chart </td>
  </tr>
  <tr>
    <td valign="top" class="text">The work of requesting the data from submitted form and creating the chart is done in the code behind page <span class="codeInline">Default.aspx.cs</span>. </td>
  </tr>
  <tr>
    <td valign="top" class="codeBlock"><p class="codeBlock"><strong>				private void ButtonChart_Click(object sender, System.EventArgs e)</strong><br>
		{<br>
			<span class="codeComment">&nbsp;//We first request the data from the form (Default.aspx)</span><br>
			&nbsp;int soups, salads, sandwiches, beverages, desserts;<br>
			&nbsp;soups = int.Parse(TextBoxSoups.Text);<br>
			&nbsp;salads = int.Parse(TextboxSalads.Text);<br>
			&nbsp;sandwiches = int.Parse(TextboxSandwiches.Text);<br>
			&nbsp;beverages = int.Parse(TextboxBeverages.Text);<br>
			&nbsp;desserts   = int.Parse(TextboxDesserts.Text);<br>
	<br>
			&nbsp;<span class="codeComment">//In this example, we're directly showing this data back on chart.<br>
&nbsp;//In your apps, you can do the required processing and then show the <br>
&nbsp;//relevant data only.<br>
	<br>
&nbsp;//Now that we've the data in variables, we need to convert this into XML.<br>
&nbsp;//The simplest method to convert data into XML is using string concatenation.</span><br>	
			&nbsp;string xmlData = String.Empty;<br>
			<span class="codeComment">&nbsp;//Initialize &lt;chart> element</span><br>
			&nbsp;xmlData = "&lt;chart caption='Sales by Product Category' subCaption='For this week' showPercentValues='1' pieSliceDepth='30' showBorder='1'&gt;";<br>
			&nbsp;<span class="codeComment">//Add all data</span><br>
			&nbsp;xmlData += "&lt;set label='Soups' value='" + soups + "' /&gt;";<br>
			&nbsp;xmlData += "&lt;set label='Salads' value='" + salads + "' /&gt;";<br>
			&nbsp;xmlData += "&lt;set label='Sandwiches' value='" + sandwiches + "' /&gt;";<br>
			&nbsp;xmlData += "&lt;set label='Beverages' value='" + beverages + "' /&gt;";<br>
			&nbsp;xmlData += "&lt;set label='Desserts' value='" + desserts + "' /&gt;";<br>
			&nbsp;<span class="codeComment">//Close &lt;chart&gt; element</span><br>
			&nbsp;xmlData += "&lt;/chart&gt;";<br>
	<br>
			<span class="codeComment">&nbsp;//Create the chart - Pie 3D Chart with data from strXML</span><br>
			&nbsp;LiteralChart.Text = FusionCharts.RenderChart("../../FusionCharts/Pie3D.swf", "", xmlData, "Sales", "500", "300", false, false);<br>
		}<br>
    
    </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><p>As you can see in the above code, we're doing the following:</p>
      <ul>
        <li>Requesting data from the submitted form and storing it in local variables when the button 'Chart it' is pressed.</li>
        <li>Creating an XML data document using string concatenation and storing it in <span class="codeInline">xmlData</span> variable </li>
        <li>Creating a Pie 3D chart using <span class="codeInline">Functions.RenderChart()</span> function and passing <span class="codeInline">xmlData</span> as <span class="codeInline">dataXML</span> for the chart. </li>
      </ul>
      <p>When you finally run the code, you'll see a chart as under: </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_FormChart.jpg" width="468" height="268" class="imageBorder" /></td>
  </tr>
</table>
</body>
</html>
